﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<PaperSystem.Models.UpdatePaper>" %>
<%@ Import Namespace="PaperSystem.Models" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>修改试卷</title>
    <link type="text/css" href="/Content/common.css" rel="Stylesheet" />
    <style type="text/css">
        body,html{overflow-x:hidden;}
        .page_center{*position:relative;}/*解决IE6/7下滚动bug */
        .page_center_inner{padding:14px 80px 0 14px;}
        
        .paper_container,
        .table_container{font-size:12px;font-family:"lucida Grande",Verdana;}
        
        /* paper_container */
        .paper_container{margin-top:10px;padding-bottom:10px;}
        .paper_content{padding:0 0 6px 0;margin:0 0 8px 0;background:#f9f9f9;
            border:1px solid #ddd;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;
        }
        .paper_content .ex_q_type{font-size:14px;margin:0 0 0 4px;}
        .paper_content_hover{border-color:#bbb;}
        .paper_content_remove_icon{display:none;width:20px;height:20px;overflow:hidden;position:absolute;z-index:11;top:2px;right:2px;cursor:pointer;background:url(/Content/images/icon.png) 0 0 no-repeat;text-indent:-9999px;}
        .paper_content_hover .paper_content_remove_icon{display:block;}
        .paper_content_placeholder{border:1px solid #fcefa1;height:100px;background:#fcefa1;}
        .q_in_q{*zoom:1;margin:4px 4px 0;}
        .q_ex_q{*zoom:1;margin:8px 4px 0;}
        .q_in_q:after,
        .q_ex_q:after{clear:both;content:"\20";display:block;height:0;}
        .q_left{float:left;width:92px;height:20px;line-height:20px;}
        .q_right{margin-left:100px;line-height:20px;}
        .info{padding:10px 0;}
        .paper_content .PIcontent {height:40px;line-height:20px;margin-left:8px;width:60%;}
        /* dragger */
        .dragger{position:absolute;left:-20px;top:0;width:20px;height:100%;cursor:pointer;background:#999 url(/Content/images/dragger_bg.png) 0 0 repeat-y;-webkit-box-shadow:-2px 0 4px 0 rgba(0,0,0,0.15);box-shadow:-2px 0 4px 0 rgba(0,0,0,0.15);}
        .dragger_inner{position:absolute;width:17px;height:62px;top:50%;left:-16px;margin-top:-31px;background:url(/Content/images/icon.png) 0 -26px no-repeat;}
        .dragger .in{background-position:-22px -26px;}
        
        /* table_container */
        .table_container{*zoom:1;position:absolute;width:800px;height:100%;right:-802px;top:0;background:#fff;border-left:1px solid #999;z-index:2000;}
        .table_container_inner{height:100%;overflow-y:auto;}
        .table_container_inner h2{font-size:14px;}
        .question_search_container{margin:4px 0;position:relative;font-size:14px;}
        .question_search_container .btn_blue{height:20px;line-height:20px;position:absolute;right:148px;top:2px;width:40px;height:40px;line-height:40px;font-size:14px;}
        .question_search_container input,
        .question_search_container select{width:120px;}
        .col_creator, .col_time, .col_course, .col_content, .col_type, .col_chapter, .col_knowledge, .col_TorE{height:100%;text-align:center;}
    </style>
</head>
<body>
    <div class="page_container">
	    <div class="page_left">
		    <div class="page_left_inner">
			    <h1 class="left_logo"><a href="#" class="logo" title="试题库系统">试题库系统</a></h1>
			    <%if (ViewData["userName"] != null){%>
			        <div class="left_message">欢迎您，<br/><%=ViewData["userName"]%>老师<br /><a href="/Login/Logout/" class="logout">退出</a></div>
			    <%} %>
			    <ul class="left_nav">
				    <li><a href="/Question/QuestionList">题库管理</a></li>
				    <li class="current"><a href="/Paper/PaperList/">试卷管理</a></li>
				    <li><a href="/Paper/PaperCorrectList1">改卷</a></li>
				    <li><a href="/Statistics/PaperList">统计</a></li>
			    </ul>
		    </div>
	    </div>
	    <!-- end page_left -->
	    <div class="page_center">
		    <div class="page_center_inner">
		    <form id="download_form" action="/Paper/PaperDownload" method="post">
		        <input type="hidden" name="pid" value="<%=Model.pid %>" />
		    </form>
		    <form action="/Paper/PaperUpdate/" method="post" id="paper_form">
			    <div class="tab_container">
				    <ul class="tab_nav">
					    <li><a href="/Paper/PaperList">查看试卷</a></li>
					    <li><a href="/Paper/PaperAdd">添加试卷</a></li>
    					<li class="current">修改试卷</li>
				    </ul>
			        <div class="tab_content">
				        <div class="tab_content_inner">
				            <input type="hidden" name="paper.pid" value="<%=Model.pid %>" />
				            <input type="hidden" name="paper.course" value="<%=Model.course %>" />
				            <input type="hidden" name="paper.TorE" value="<%=Model.TorE %>" />
				            <input type="hidden" name="paper.creatorId" value="<%=Model.creatorId %>" />
				            <input type="hidden" name="paper.createTime" value="<%=Model.createTime %>" />
				            <label>试卷名称:</label><input type="text" name="paper.paperTitle" value="<%=Model.paperTitle %>" class="data_confirm" data-confirm="required reHTML" />
				            <label>语种:</label><%=Model.course %>
				            <label>试卷用途:</label><%=Model.TorE%>
				            <label>限时(分钟):</label><input type="text" name="paper.usedMinute" value="<%=Model.usedMinute %>" class="data_confirm" data-confirm="required int"/>
				            <% if (Model.pid != -1)
                            {%>
				            <a href="#" id="btn_download" class="btn_gray" onclick="document.getElementById('download_form').submit();">导出word</a>
				            <%} %>
				        </div>
			        </div>
			    </div>
			    <!-- end tab_container -->
			    <!-- content begin here -->
			    <% if (Model.pid != -1){%>
			    <div class="paper_container" id="paper_container">
			        <div id="paper_content">
			             <% UpdatePaperObject[] paperObject = Model.paperObject as UpdatePaperObject[];
			                UpdatePaperInfo[] paperInfo = Model.paperInfo as UpdatePaperInfo[];

                            int current_eid = -1;
                            int cnt_info = 0;
			                int cnt_obj = 0;         
			                bool is_first_obj = true; 
                            foreach (var each_obj in paperObject)
                            {
                                //如果eid改变就
                                if (each_obj.eid != current_eid)
                                {
                                    current_eid = each_obj.eid;
                                    //如果不是第一个obj，且eid改变就输出大题的尾
                                    if (!is_first_obj)
                                    {
                                    %>
                                    </div> 
                                    <%
                                    }
                                    else
                                    {
                                        is_first_obj = false;
                                    }
                                    while (cnt_info < paperInfo.Length && (int.Parse(paperInfo[cnt_info].before) == each_obj.POorder))
                                    {
                                    %>
                                        <div class="sortable paper_content info">
                                            <textarea class="replace_order PIcontent" data-confirm="required reHTML" name="paperInfo[<%=cnt_info %>].PIcontent"><%=paperInfo[cnt_info].PIcontent%></textarea>
                                            <input type="hidden" class="replace_order PIorder" name="paperInfo[<%=cnt_info %>].PIorder" value="<%=paperInfo[cnt_info].PIorder %>" />
                                            <input type="hidden" class="replace_order before" name="paperInfo[<%=cnt_info %>].before" value="<%=paperInfo[cnt_info].before %>"/>
                                        </div>
                                    <%
                                        cnt_info++;
                                    }
                                    //输出大题的头、大题的信息
                                    string content_title = "";
                                    switch (each_obj.type)
                                    {
                                        case "阅读理解": content_title = "文章："; break;
                                        case "完形填空": content_title = "文章："; break;
                                        case "翻译": content_title = "原文："; break;
                                        case "作文": content_title = "作文要求："; break;
                                        case "综合选择": content_title = "题目："; break;
                                        case "词语搭配": content_title = "题干："; break;
                                    }
                                    %>
                                        <div class="sortable paper_content ex_q" data-eid="<%=each_obj.eid %>">
                                            <h3 class="ex_q_type"><%=each_obj.type %></h3>
                                            <div class="q_ex_q">
                                                <label class="q_left"><%=content_title %></label>
                                                <div class="q_right"><%=each_obj.content.Replace("\n","<br/>") %></div>
                                            </div>
                                    <%
                                }
                                //输出小题的信息
                                %>
                                    <div class="q_in_q">
                                        <input type="hidden" class="Iid replace_order" name="paperObject[<%=cnt_obj %>].Iid" value="<%=each_obj.Iid %>">
                                        <%if (each_obj.Icontent != null){ %>
                                            <label class="q_left">题目：</label><div class="q_right"><%=each_obj.Icontent.Replace("\n","<br/>")%></div>
                                        <%}if (each_obj.answer != null){ %>
                                            <label class="q_left">参考答案：</label><div class="q_right"><%=each_obj.answer.Replace("\n", "<br/>")%></div>
                                        <%}if (each_obj.option1 != null){ %>
                                            <label class="q_left choice_A">A:</label><div class="q_right choice_A"><%=each_obj.option1%></div>
                                        <%}if (each_obj.option2 != null){ %>
                                            <label class="q_left choice_B">B:</label><div class="q_right choice_B"><%=each_obj.option2%></div>
                                        <%}if (each_obj.option3 != null){ %>
                                            <label class="q_left choice_C">C:</label><div class="q_right choice_C"><%=each_obj.option3%></div>
                                        <%}if (each_obj.option4 != null){ %>
                                            <label class="q_left choice_D">D:</label><div class="q_right choice_D"><%=each_obj.option4%></div>
                                        <%}if (each_obj.option5 != null){ %>
                                            <label class="q_left choice_E">E:</label><div class="q_right choice_E"><%=each_obj.option5%></div>
                                        <%}if (each_obj.option6 != null){ %>
                                            <label class="q_left choice_F">F:</label><div class="q_right choice_F"><%=each_obj.option6%></div>
                                        <%}if (each_obj.option7 != null){ %>
                                            <label class="q_left choice_G">G:</label><div class="q_right choice_G"><%=each_obj.option7%></div>
                                        <%}if (each_obj.option8 != null){ %>
                                            <label class="q_left choice_H">H:</label><div class="q_right choice_H"><%=each_obj.option8%></div>
                                        <%} %>
                                        <label class="q_left">分值:</label>
                                        <input type="text" name="paperObject[<%=cnt_obj %>].point" value="<%=each_obj.point %>" class="replace_order data_confirm score" data-confirm="required float">
                                        <input type="hidden" class="replace_order POorder" name="paperObject[<%=cnt_obj %>].POorder" value="<%=each_obj.POorder %>">
                                    </div>
                                <%
                                cnt_obj++;
                            }                  
			                //最后输出一个大题的尾部
                            %>
                            </div>   
                            <%
                            //如果还有信息没输出
                            while (cnt_info < paperInfo.Length)
                            {
                             %>
                                <div class="sortable paper_content info">
                                    <textarea class="replace_order PIcontent" data-confirm="required reHTML" name="paperInfo[<%=cnt_info %>].PIcontent"><%=paperInfo[cnt_info].PIcontent%></textarea>
                                    <input type="hidden" class="replace_order PIorder" name="paperInfo[<%=cnt_info %>].PIorder" value="<%=paperInfo[cnt_info].PIorder %>" />
                                    <input type="hidden" class="replace_order before" name="paperInfo[<%=cnt_info %>].before" value="<%=paperInfo[cnt_info].before %>"/>
                                </div>
                            <%
                                cnt_info++;
                            }
			             %>
			             
			        </div>
			        <div class="clearfix">
			            <a href="#" class="btn_blue" id="save_paper">完成试卷</a>
			        </div>
			    </div>
			    <div class="scroll_wrap">
			        <a href="#" class="up" title="滚动到顶部">UP</a>
			        <a href="#" class="down" title="滚动到底部">DOWN</a>
			    </div>
			    <% }else{ %>
			        <div class="txt_center" style="padding:40px 0;">您找的试卷不存在。</div>
			    <%} %>
			    <!-- content end here -->
			    <input type="hidden" id="begin_message" value="<%=TempData["begin_message"] %>"/>
			</form>
		    </div>
	    </div>
	    <!-- end page_center -->
    </div>
<script type="text/javascript" src="/Scripts/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="/Scripts/common.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        //滚动到顶部/底部
        $('.scroll_wrap').on('click', 'a', function() {
            if ($(this).hasClass('up')) {
                $('.page_center').animate({ scrollTop: 0 }, 200);
            } else {
                $('.page_center').animate({ scrollTop: $('.page_center_inner').height() }, 200);
            }
            return false;
        });
        //计算整张试卷的总分数
        function getScore() {
            var obj_score = $('.score'),
                score = 0;
            obj_score.each(function(index, elem) {
                score += parseFloat($(elem).val());
            });
            return score || 0;
        }

        //鼠标移上
        $('#paper_content').on('mouseenter', '.paper_content', function() {
            $(this).addClass('paper_content_hover');
        })
        .on('mouseleave', '.paper_content', function() {
            $(this).removeClass('paper_content_hover');
        });


        //完成试卷
        $('#save_paper').on('click', function() {
            if ($('.paper_content').length == 0) {
                message('尚未添加任何题目或信息到试卷上', 'error', true, 5000);
                return false;
            }
            if (isInputOK()) {
                //order_all_things();
                if (confirm('当前试卷总分为 ' + getScore() + ' ,确认提交试卷?')) {
                    document.getElementById('paper_form').submit();
                }
            }

        });

    });
</script>
</body>
</html>
